package com.example.listener.utils;

import android.content.ContentResolver;
import android.content.Context;
import android.media.AudioManager;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.provider.Settings;

/**
 * @author xct
 * create on: 2022/8/30 11:05
 */
public class SystemUtil {
    /**
     * 获取当前wifi强度
     */
    public static final int WIFI_SIGNAL_STRONG = 3; // wifi信号强/满格
    public static final int WIFI_SIGNAL_NORMAL = 2; // 信号偏差
    public static final int WIFI_SIGNAL_WEAK = 1; // 信号弱
    public static final int WIFI_SIGNAL_NONE = 0; // 无信号

    public static int getWifiStrength(Context context) {
        WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
        if (wifiManager == null || !wifiManager.isWifiEnabled()) {
            return WIFI_SIGNAL_NONE;
        }
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        int rssi = wifiInfo.getRssi();
        return WifiManager.calculateSignalLevel(rssi, 4);
    }


    public static int getSystemBrightness(ContentResolver cr) {
        int systemBrightness = 0;
        try {
            systemBrightness = Settings.System.getInt(cr, Settings.System.SCREEN_BRIGHTNESS);
        } catch (Settings.SettingNotFoundException e) {
            e.printStackTrace();
        }
        return systemBrightness;
    }

    public static int getVolume(Context context,int streamType){
        AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        return audioManager.getStreamVolume(streamType);
    }
    public static int getVolumeMax(Context context,int streamType){
        AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        return audioManager.getStreamMaxVolume(streamType);
    }
}
